home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-13 | 29.3 KB | 1,123 lines | [TEXT/MPS ] |
- /*------------------------------------------------------------------------------
-
- File: TextEditorImaging.cpp
-
- Description: TextEditor's imaging protocol methods.
-
- Written by: Steve Smith
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- ------------------------------------------------------------------------------*/
-
- // Notification that this is a SOM source file
- #define SampleCode_TextEditor_Class_Prototypes
- // define underscore (_) field names
- #define VARIABLE_MACROS
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (e.g. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- TextEditor Includes
-
- #ifndef _TEXTEDITORDEF_
- #include "TextEditorDef.h"
- #endif
-
- #ifndef SOM_SampleCode_TextEditor_xih
- #include "TextEditor.xih"
- #endif
-
- #ifndef _TEXTEDITORUTILS_
- #include "TextEditorUtils.h"
- #endif
-
- #ifndef _TEXTEDITORGLOBALS_
- #include "TextEditorGlobals.h"
- #endif
-
- #ifndef _STDTEXTPROPERTIES_
- #include "StdTextProps.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- // -- Macintosh Includes --
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- // -- Textension Includes --
-
- #ifndef _Textension_
- #include "Textension.h"
- #endif
-
- #ifndef _QDTextRun_
- #include "QDTextRun.h"
- #endif
-
- #ifndef _RulerObject_
- #include "RulerObject.h"
- #endif
-
- #ifndef _Frames_
- #include <Frames.h>
- #endif
-
- #ifndef _LinkedFrames_
- #include "LinkedFrames.h"
- #endif
-
-
- //------------------------------------------------------------------------------
- // Method: GenerateThumbnail
- // Origin: TextEditor
- //
- // Description: This method is called by the part to generate a thumbnail view
- // from the current content.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__GenerateThumbnail
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","GenerateThumbnail");
-
- SOM_TRY
-
- // In cases where a part has been instantiated from scratch and has no
- // content (yet), it is appropriate to display a PICT or some graphic
- // in place of a "real" thumbnail.
-
- //$$$$$ if not content
- LoadThumbnail(ev, &gGlobals->fThumbnail);
-
- // If we were unable to load the PICT resource for whatever reason
- // we will default back to a "frame" view and throw the Resource
- // Manager error as an exception.
- if ( gGlobals->fThumbnail == kODNULL )
- {
- frame->ChangeViewType(ev, gGlobals->fFrameView);
-
- // There is a bug in ResError, when resources are not found,
- // which may cause noErr to be returned. If that is the case,
- // we throw resNotFound.
- THROW_IF_ERROR(ResError());
- THROW(resNotFound);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: FacetAdded
- // Origin: TextEditor
- //
- // Description: This method is called when any part adds a facet to
- // one of our display frames.
- //
- // The part calls ViewTypeChanged to load the appropriate
- // resource for display in this facet and then activates
- // the frame if we are the root part of an active window.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__FacetAdded
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","FacetAdded");
-
- SOM_TRY
-
- ODFrame* frame = facet->GetFrame(ev);
-
- // We need to do nothing special for the ruler frame/facet.
- if ( frame->GetPresentation(ev) == gGlobals->fRulerPresentation )
- return;
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- CFocus initiateDrawing(ev, facet);
-
- // We need to Initialize Textension based on the scope of part
- // this instance is, either "root" or "embedded". We do it here
- // because this is the first place where it is possible to determine
- // the part scope when an existing document is opened.
-
- if ( !_fTextensionInitialized )
- {
- somSelf->InitializeTextension(ev, frame->IsRoot(ev));
-
- _fTextension->SetTextPort(facet->GetCanvas(ev)->GetQDPort(ev));
-
- // Read the contents of the document.
- somSelf->InternalizeContent(ev, somSelf->GetStorageUnit(ev), kODNULL);
-
- // After internalizing the content, we examine the ruler object to
- // determine the justification of the saved document.
- long length;
- char just;
-
- const CRulerObject* ruler = _fTextension->GetNextRuler((long)0, &length);
- if ( ruler )
- ruler->GetAttributeValue(kJustAttr, &just);
- /* else
- {
- somSelf->DoDialogBox(ev, frame, kErrorBoxID, kErrTxCreateObjectFailed);
-
- //$$$$$ go through the protocol of removing this frame!
- }
- */
-
- switch ( just )
- {
- case kLeftJust: _fTextAlignment = left; break;
- case kCenterJust: _fTextAlignment = center; break;
- case kRightJust: _fTextAlignment = right; break;
- case kFullJust: _fTextAlignment = fulljustification; break;
- default:
- _fTextAlignment = left;
- }
- }
-
- if ( frame->IsRoot(ev) )
- {
- // Calculate the size of the ViewRect for this root frame.
- somSelf->CalcViewRect(ev, frame);
- }
- else
- {
- // Calculate the usable area for this embedded frame.
- TLongRect textBounds;
- ODRect bounds;
-
- TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
- frameShape->GetBoundingBox(ev, &bounds);
-
- textBounds.top = FixedToInt(bounds.top);
- textBounds.left = FixedToInt(bounds.left);
- textBounds.bottom = FixedToInt(bounds.bottom);
- textBounds.right = FixedToInt(bounds.right);
-
- CVariableSizeFrames* frames =
- (CVariableSizeFrames*) _fTextension->GetFramesHandler();
-
- CDisplayChanges changes;
- frames->AddFrame(0, textBounds, &changes);
-
- (void) _fTextension->DisplayChanged(changes);
- }
-
- // Set the text bounds and margins for the frame
- somSelf->CalcTextBounds(ev, frame);
-
- TOffsetRange selRange(_fTextension->CountCharsBytes(), _fTextension->CountCharsBytes());
- _fTextension->SetSelectionRange(selRange);
-
- somSelf->ViewTypeChanged(ev, frame);
- // We call this to prepare our part for being displayed in one of
- // the four standard views: Large Icon, Small Icon, Frame, and
- // Thumbnail.
-
- if ( frame->IsRoot(ev) )
- {
- // If a root facet is being added, the frame should be activated when the
- // window is "selected". This prevents OpenDoc from getting into an
- // ambiguous state of no part having the selection focus.
- frameInfo->SetFrameReactivate(kODTrue);
- // We set the active facet even though the window may not become active
- // because Textension requires a valid facet for drawing.
- frameInfo->SetActiveFacet(facet);
-
- // Add scroll bars
-
- ODRect bbox;
- Rect frameRect;
- Rect scrollBarRect;
-
- TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
- frameShape->GetBoundingBox(ev, &bbox);
-
- FixedToIntRect(bbox, frameRect);
-
- scrollBarRect = frameRect;
- scrollBarRect.left = scrollBarRect.right - 15;
- scrollBarRect.right += 1;
- scrollBarRect.top -= 1;
- scrollBarRect.bottom -= 14;
- _fVScrollbar = NewControl(facet->GetCanvas(ev)->GetQDPort(ev),
- &scrollBarRect, "\p", true,
- 0/*val*/, 0/*min*/, 0/*max*/,
- scrollBarProc, 0);
-
- scrollBarRect = frameRect;
- scrollBarRect.left -= 1;
- scrollBarRect.right -= 14;
- scrollBarRect.top = scrollBarRect.bottom - 15;
- scrollBarRect.bottom += 1;
- _fHScrollbar = NewControl(facet->GetCanvas(ev)->GetQDPort(ev),
- &scrollBarRect, "\p", true,
- 0/*val*/, 0/*min*/, 0/*max*/,
- scrollBarProc, 0);
-
- somSelf->AdjustScrollbars(ev, frame);
- }
- else
- {
- // If a frame had all of its facets removed, the frame would have
- // hidden any of its part windows. If the frame becomes visible again,
- // by having a facet added to it, we will "show" the part window for
- // the frame.
-
- if ( CountFacets(ev, frame) == 1 )
- {
- TempODWindow window = frameInfo->AcquirePartWindow(ev);
- if ( window )
- window->Show(ev);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: FacetRemoved
- // Origin: ODPart
- //
- // Description: This method is called when any part removes a facet
- // from one of our display frames.
- //
- // The part just removes the "active" note from the
- // appropriate display frame if necessary since this
- // facet will not be available, nor active, again.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__FacetRemoved
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","FacetRemoved");
-
- SOM_TRY
-
- ODFrame* frame = facet->GetFrame(ev);
-
- // We need to do nothing special for the ruler frame/facet.
- if ( frame->GetPresentation(ev) != gGlobals->fRulerPresentation )
- {
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // If the facet was the active facet, it can no longer be.
- if (frameInfo->GetActiveFacet() == facet)
- frameInfo->SetActiveFacet(kODNULL);
-
- // If a frame has all of its facets removed, the frame becomes
- // "hidden". If the frame a part window, the part window should also
- // be hidden.
-
- if ( CountFacets(ev, frame) == 0 && containingFrame == kODNULL )
- {
- TempODWindow window = frameInfo->AcquirePartWindow(ev);
- if ( window )
- window->Hide(ev);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: Draw
- // Origin: ODPart
- //
- // Description: This method is called when a facet of a part's display
- // frame intersects the invalidated portion of an OpenDoc
- // window. The invalidShape parameter passed in is the
- // portion of the facet which has been invalidated.
- //
- // The part sets up the drawing environment using a
- // C++ helper class (CFocus) and then calls the
- // appropriate drawing method based on the frame's
- // viewType.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__Draw
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- ODShape* invalidShape
- )
- {
- SOMMethodDebug("TextEditor","Draw");
-
- SOM_TRY
-
- // Focus the port and origin for drawing in our facet.
- // Note that this instance of the CFocusDrawingEnv class
- // is being allocated on the stack. When the execution
- // leaves the scope of this method, the destructor (which
- // cleans up the drawing environment) is automatically
- // called.
- CFocus initiateDrawing(ev, facet);
-
- ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
-
- if ( view == gGlobals->fLargeIconView || view == gGlobals->fSmallIconView )
- somSelf->DrawIconView(ev, facet);
- else if ( view == gGlobals->fThumbnailView )
- somSelf->DrawThumbnailView(ev, facet);
- else
- somSelf->DrawFrameView(ev, facet);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawFrameView
- // Origin: TextEditor
- //
- // Description: This method is called by the part when the frame being
- // drawn is in "frame" view.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__DrawFrameView
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DrawFrameView");
-
- SOM_TRY
-
- GrafPtr thePort;
- GetPort(&thePort);
- EraseRect(&thePort->portRect);
-
- ODFrame* frame = facet->GetFrame(ev);
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- ODRect bbox;
- Rect updateRect;
-
- // Draw the scrollbars, if we have them.
- if ( frame->IsRoot(ev) )
- {
- Draw1Control(_fVScrollbar);
- Draw1Control(_fHScrollbar);
- }
-
- TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
- frameShape->GetBoundingBox(ev, &bbox);
-
- FixedToIntRect(bbox, updateRect);
-
- // Subtract the scrollbars from the update area, if we have them.
- if ( frame->IsRoot(ev) )
- {
- updateRect.right -= 15;
- updateRect.bottom += 15;
- }
-
- _fTextension->SetTextPort(facet->GetCanvas(ev)->GetQDPort(ev));
- _fTextension->Draw(updateRect, kNoDrawFlags);
-
- // Frame the text bounds to make the margins visible.
- if ( frame->IsRoot(ev) )
- somSelf->DrawPageBounds(ev);
- }
- else
- {
- CUsingLibraryResources res;
-
- PicHandle pict = GetPicture(kRulerPictResID);
-
- if (pict)
- {
- Rect pictRect = (**pict).picFrame;
- OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
-
- DrawPicture(pict, &pictRect);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawPageBounds
- // Origin: TextEditor
- //
- // Description: This method is called by the part when the page bounds need to
- // be drawn.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__DrawPageBounds
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DrawPageBounds");
-
- SOM_TRY
-
- Rect pageRect;
- Rect viewRect;
- RgnHandle saveClip;
-
- PenNormal();
- PenPat(&ODQDGlobals.gray);
-
- _fTextension->GetViewRect(&viewRect);
-
- GetClip(saveClip = NewRgn());
- ClipRect(&viewRect);
-
- CFrames* frames = _fTextension->GetFramesHandler();
-
- for (int i = 0; i < frames->GetCountFrames(); i++)
- {
- frames->GetTextBounds(i, &pageRect);
-
- InsetRect(&pageRect, -3, -3);
- FrameRect(&pageRect);
- }
-
- PenNormal();
-
- SetClip(saveClip);
- DisposeRgn(saveClip);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawIconView
- // Origin: TextEditor
- //
- // Description: This method is called by the part when the frame being
- // drawn is in "standard icon" view.
- //
- // The part uses the Icon Utilities toolbox manager to
- // aid in drawing icons in active windows. The Guidelines
- // require a different appearance for selected icons in
- // inactive windows, which we do manually.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__DrawIconView
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DrawIconView");
-
- SOM_TRY
-
- IconTransformType transformType = ttNone;
- ODFrame* frame = facet->GetFrame(ev);
- ODTypeToken viewType = frame->GetViewType(ev);
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // Check to see if the facet is selected
- if ( facet->GetHighlight(ev) == kODFullHighlight )
- transformType = ttSelected;
-
- // Check to see if the frame has been opened into a part window.
- TempODWindow window = frameInfo->AcquirePartWindow(ev);
- if ( window && window->IsShown(ev) )
- transformType |= ttOpen;
-
- // Draw the icon.
- Rect iconRect;
- SetRect(&iconRect, 0, 0,
- (viewType == gGlobals->fLargeIconView) ? kODLargeIconSize : kODSmallIconSize,
- (viewType == gGlobals->fLargeIconView) ? kODLargeIconSize : kODSmallIconSize);
-
- CUsingLibraryResources res;
- PlotIconID(&iconRect, atAbsoluteCenter, transformType, kBaseResourceID);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawThumbnailView
- // Origin: TextEditor
- //
- // Description: This method is called by the part when the frame being
- // drawn is in "thumbnail" view.
- //
- // The part uses a picture for its thumbnail view because
- // it has no intrinsic content. A picture resource is
- // probably not sufficient for parts with real content.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__DrawThumbnailView
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SOMMethodDebug("TextEditor","DrawThumbnailView");
-
- SOM_TRY
-
- LoadThumbnail(ev, &gGlobals->fThumbnail);
-
- Rect bounds = (**(PicHandle) gGlobals->fThumbnail).picFrame;
-
- OffsetRect(&bounds, -bounds.left, -bounds.top);
- DrawPicture((PicHandle) gGlobals->fThumbnail, &bounds);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: GeometryChanged
- // Origin: ODPart
- //
- // Description: This method is called when the ExternalTransform or
- // ClipShape of a facet on one this part's display frames
- // changes.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__GeometryChanged
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- ODBoolean clipShapeChanged,
- ODBoolean externalTransformChanged
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","GeometryChanged");
-
- SOM_TRY
-
- // Typically, when the frameshape changes, you want to invalidate only the "new"
- // area. However, TextEditor's display changes based on the frame shape so we
- // must invalidate the entire area.
-
- if ( clipShapeChanged )
- // Specifying kODNULL means to invalidate the clipShape (which was
- // calculated from the usedShape).
- facet->Invalidate(ev, kODNULL, kODNULL);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: HighlightChanged
- // Origin: ODPart
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__HighlightChanged
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HighlightChanged");
-
- SOM_TRY
-
- ODFrame* frame = facet->GetFrame(ev);
-
- // The frame view has no "special" drawing characteristics
- // when opened or selected, so we don't need to update our
- // content.
-
- //$$$$$ shouldn't we change Textension from active to inactive
- // hilighting?
-
- if ( frame->GetViewType(ev) != gGlobals->fFrameView )
- frame->Invalidate(ev, kODNULL, kODNULL);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: CalcViewRect
- // Origin: TextEditor
- //
- // Description: This method is called when a facet....
- //
- // Note: This routine only works on root frames.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__CalcViewRect
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","CalcViewRect");
-
- SOM_TRY
-
- WASSERT(frame && frame->IsRoot(ev));
-
- ODRect bbox;
- Rect viewRect;
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
- frameShape->GetBoundingBox(ev, &bbox);
-
- FixedToIntRect(bbox, viewRect);
-
- if ( frame->IsRoot(ev) )
- {
- viewRect.right -= 15;
- viewRect.bottom -= 15;
- }
-
- _fTextension->SetViewRect(viewRect);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: CalcTextBounds
- // Origin: TextEditor
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__CalcTextBounds
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","CalcTextBounds");
-
- SOM_TRY
-
- Rect textBounds;
-
- if ( frame->IsRoot(ev) )
- {
- textBounds = _fPaperSize;
-
- textBounds.top += _fPageMargins.top;
- textBounds.left += _fPageMargins.left;
- textBounds.bottom -= _fPageMargins.bottom;
- textBounds.right -= _fPageMargins.right;
- }
- else
- {
- ODRect bbox;
- TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
- frameShape->GetBoundingBox(ev, &bbox);
-
- FixedToIntRect(bbox, textBounds);
- }
-
- CFrames* frames = _fTextension->GetFramesHandler();
- TLongPoint size((textBounds.right-textBounds.left), (textBounds.bottom-textBounds.top));
-
- CDisplayChanges displayChanges;
-
- frames->SetTextBoundsSize(size, &displayChanges, 0);
- frames->SetFramesOrigin(0,0);
- frames->SetFramesMargins(_fPageMargins);
-
- short action = _fTextension->DisplayChanged(displayChanges);
-
- if ( action & kRedrawAll )
- frame->Invalidate(ev, kODNULL, kODNULL);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustScrollbars
- // Origin: TextEditor
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__AdjustScrollbars
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AdjustScrollbars");
-
- SOM_TRY
-
- if ( frame->IsRoot(ev) )
- {
- Rect viewRect;
- _fTextension->GetViewRect(&viewRect);
-
- TLongPoint scrolledVals;
- _fTextension->GetScrolledValues(&scrolledVals);
-
- ODSLong max = _fTextension->GetTotalHeight()
- - (viewRect.bottom - viewRect.top);
- if ( max < 0 )
- {
- // Deactivate the scrollbar.
- HiliteControl( _fVScrollbar, 255);
- }
- else
- {
- HiliteControl(_fVScrollbar, 0);
- SetControlMaximum(_fVScrollbar, max);
- SetControlValue(_fVScrollbar, scrolledVals.v);
- }
-
- max = _fTextension->GetTotalWidth() - (viewRect.right - viewRect.left);
-
- if ( max < 0 )
- {
- // Deactivate the scrollbar.
- HiliteControl(_fHScrollbar, 255);
- }
- else
- {
- HiliteControl(_fHScrollbar, 0);
- SetControlMaximum(_fHScrollbar, max);
- SetControlValue(_fHScrollbar, scrolledVals.h);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: CalcSelectionRgn
- // Origin: TextEditor
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__CalcSelectionRgn
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","CalcSelectionRgn");
-
- SOM_TRY
-
- CFocus initiateDrawing(ev, facet);
-
- OpenRgn();
-
- _fTextension->GetSelectionHandler()->Draw();
-
- ODRgnHandle selectionRgn = ODNewRgn();
- CloseRgn(selectionRgn);
-
- if ( selectionRgn )
- {
- ODDisposeHandle((ODHandle) _fSelectionRgn);
- _fSelectionRgn = (Handle) selectionRgn;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: PresentationChanged
- // Origin: ODPart
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__PresentationChanged
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","PresentationChanged");
- }
-
- //------------------------------------------------------------------------------
- // Method: RepositionScrollbars
- // Origin: TextEditor
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__RepositionScrollbars
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","RepositionScrollbars");
-
- SOM_TRY
-
- ODRect bbox;
- Rect frameRect;
- Rect scrollBarRect;
-
- TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
- frameShape->GetBoundingBox(ev, &bbox);
-
- FixedToIntRect(bbox, frameRect);
-
- scrollBarRect = frameRect;
- scrollBarRect.left = scrollBarRect.right - 15;
- scrollBarRect.right += 1;
- scrollBarRect.top -= 1;
- scrollBarRect.bottom -= 14;
-
- MoveControl(_fVScrollbar, scrollBarRect.left, scrollBarRect.top);
- SizeControl(_fVScrollbar, 16, (scrollBarRect.bottom - scrollBarRect.top));
-
- scrollBarRect = frameRect;
- scrollBarRect.left -= 1;
- scrollBarRect.right -= 14;
- scrollBarRect.top = scrollBarRect.bottom - 15;
- scrollBarRect.bottom += 1;
-
- MoveControl(_fHScrollbar, scrollBarRect.left, scrollBarRect.top);
- SizeControl(_fHScrollbar, (scrollBarRect.right - scrollBarRect.left), 16);
-
- somSelf->AdjustScrollbars(ev, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: CanvasChanged
- // Origin: ODPart
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__CanvasChanged
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","CanvasChanged");
- }
-
- //------------------------------------------------------------------------------
- // Method: CanvasUpdated
- // Origin: ODPart
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope void
- SOMLINK TextEditor__CanvasUpdated
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODCanvas* canvas
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","CanvasUpdated");
- }
-
- //------------------------------------------------------------------------------
- // Method: GetPrintResolution
- // Origin: ODPart
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
- #pragma segment TextEditorImaging
-
- SOM_Scope ODULong
- SOMLINK TextEditor__GetPrintResolution
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","GetPrintResolution");
-
- return kMinImagingResolution;
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustBorderShape
- // Origin: ODPart
- //
- // Description: This method is called by
- //------------------------------------------------------------------------------
- #pragma segment TextEditorLayout
-
- SOM_Scope ODShape*
- SOMLINK TextEditor__AdjustBorderShape
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* embeddedFacet,
- ODShape* shape
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AdjustBorderShape");
-
- SOM_TRY
- ODAcquireObject(ev, shape);
- SOM_CATCH_ALL
- shape = kODNULL;
- SOM_ENDTRY
-
- return shape;
- }
-
-